package teach.shuji.java12.system.controller;

//6. 写控制器

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import teach.shuji.java12.common.CommonResult;
import teach.shuji.java12.common.NoDataCommonResult;
import teach.shuji.java12.system.dto.roles.GetUserByRoleQuery;
import teach.shuji.java12.system.dto.roles.RoleAddDto;
import teach.shuji.java12.system.dto.roles.RoleListQuery;
import teach.shuji.java12.system.entity.Role;
import teach.shuji.java12.system.entity.User;
import teach.shuji.java12.system.service.RoleService;

import java.util.List;

@RequestMapping("role")
@RestController
public class RoleController {

    @Autowired
    RoleService roleService;


    @PostMapping("add")
    @SaCheckPermission("sys.role.add")
    public NoDataCommonResult add(RoleAddDto role) {
        return roleService.add(role);
    }

    @PutMapping("edit")
    @SaCheckPermission("sys.role.edit")
    public NoDataCommonResult edit(RoleAddDto role) {
        return roleService.edit(role);
    }

    @DeleteMapping("delete")
    @SaCheckPermission("sys.role.delete")
    public NoDataCommonResult delete(long id) {
        return roleService.delete(id);
    }

    @GetMapping("list")
    @SaCheckPermission("sys.role.query")
    public CommonResult<List<Role>> list(RoleListQuery query) {
        return roleService.list(query);
    }

    @GetMapping("getUserByRoleId")
    @SaCheckPermission("sys.role.query")
    public CommonResult<List<User>> getUserByRoleId(GetUserByRoleQuery id) {
        return roleService.getUserByRoleId(id);
    }
}
